home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6782 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  65 lines

  1. Path: canopus.cc.umanitoba.ca!natewild
  2. From: natewild@mbnet.mb.ca (Nathan T. Wild)
  3. Newsgroups: comp.lang.c++,comp.os.msdos.programmer
  4. Subject: Function Pointers In C++
  5. Date: Thu, 08 Feb 1996 13:25:54 -0500
  6. Organization: WankerNET - Digital TimeWasters Inc.
  7. Message-ID: <yAkGxc9nXE/T083yn@mbnet.mb.ca>
  8. NNTP-Posting-Host: access.mbnet.mb.ca
  9. Originator: natewild@access.mbnet.mb.ca
  10.  
  11.  
  12. I have a class which contains function pointers.  The actual code for these
  13. functions is dynamically loaded from disk at run time.  I seem to be having
  14. troubles setting these pointers???  I have done this before in C, but I
  15. guess C is a little more forgiving than C++ with respect to type checking.
  16. The declaration for my class is as follows (byte is a typedef to unsigned
  17. char):
  18.  
  19.  
  20. class MyClass {
  21.   public:
  22.     byte    (far *Init)(void);        
  23.     byte (far *Reset)(void);        
  24.     byte (far *Enable)(void);
  25.     byte (far *Disable)(void);
  26.     byte (far *Close)(void);
  27. };
  28.  
  29.      
  30. In the constructor for this class, I call a function which reads the code
  31. into an allocated block and another function which returns a pointer to the
  32. functions.  The driver files that are loaded from disk contain an offset
  33. (from the start of the driver code) to where each function exists within
  34. the driver.  The following line is the critical line in the function
  35. "GetFunctionPtr" used to determine the address of each function.
  36.  
  37.  
  38. driverPtr is the pointer to the loaded driver's start.
  39. num is the effective offset for the desired function.
  40.  
  41. return MK_FP(FP_SEG(driverPtr), peek(FP_SEG(driverPtr), (FP_OFF(driverPtr) + num)));
  42.  
  43.  
  44. In the constructor I am trying to execute code as follows:
  45.  
  46. Init = GetFunctionPtr(1);
  47. Reset= GetFunctionPtr(2);
  48. ...
  49. etc.
  50.  
  51. I get no end to the type error messages.  GetFunctionPtr returns a void far *
  52. and I am not sure how to cast it to a "pointer to a function returning a
  53. byte"...
  54.  
  55. Please give me a push in the right direction...  RSVP via Email if
  56. possible, I co not carry this group "live"...
  57.  
  58.  
  59. |--------------------------------------------------------------------|
  60. | ooooO (``)   (``) Ooooo | Nathan T. Wild                           | 
  61. | (   ) )  (   )  ( (   ) | natewild@mbnet.mb.ca                     |
  62. | )  (  (   ) (   ) )  (  | ftp://ftp.mbnet.mb.ca/pub/natewild       |
  63. | (__)  ooooO Ooooo (__)  | http://www.mbnet.mb.ca/~natewild         |
  64. |--------------------------------------------------------------------|
  65.